package com.heima.schedule.feign;

import com.heima.apis.schedule.IscheduleClient;
import com.heima.model.common.dtos.common.ResponseResult;
import com.heima.model.common.dtos.common.TaskDto;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ScheduleClient implements IscheduleClient {
    @Autowired
    private TaskService taskService;
    /**
     * 添加任务
     * @param taskDto
     * @return
     */
    @PostMapping("/api/v1/task/add")
    public ResponseResult addTask(TaskDto taskDto) {
        return taskService.addTask(taskDto);
    }
    /**
     * 取消任务
     * @param taskId        任务id
     * @return              取消结果
     */
    @GetMapping("/api/v1/task/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") long taskId) {
        return taskService.cancelTask(taskId);
    }

    /**
     * 按照类型和优先级来拉取任务
     * @param type
     * @param priority
     * @return
     */
    @PostMapping("/api/v1/task/{type}/{priority}")
    public ResponseResult pull(@PathVariable("type") int type,@PathVariable("priority") int priority) {
        return taskService.pull(type, priority);
    }
}
